<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Carbon;

class SchoolGate extends  Model
{
    use HasFactory;
    use SoftDeletes;

    static $unguarded = true;

    protected $table = 'school_gates';

    /**
     * 根据ID获取数据
     *
     * @param $id
     * @param array $columns
     * @return array|Builder
     */
    public static function getDataByID($id, array $columns = array()){
        if($columns){
            return self::query()->find($id,$columns);
        }
        $val = self::query()->find($id);
        $status_show =  getStatusValue($val['status']);
//        $status_html_show = getStatusHTMLValue($val['status']);
        return [
            'id'=>$val['id'],
            'name'=>$val['name'],
            'status'=>$val['status'],
            'sort'=>$val['sort'],
            'status_show'=>$status_show,
//            'status_html_show'=>$status_html_show,
            'created_at'=>Carbon::parse($val['created_at'])->toDateTimeString(),
            'updated_at'=>Carbon::parse($val['updated_at'])->toDateTimeString(),
       ];
    }

    /**
     * @param array $where
     * @return Builder[]|Collection
     */
    public static function getAllData(array $where = array())
    {
        if($where){
            $data = self::query()->where($where)->oldest('first_letter')->oldest('sort')->get();
        }else{
            $data = self::query()->oldest('first_letter')->oldest('sort')->get();
        }
        return $data;
    }

}
